<!--
NewProducts.xslt

Xsl transformation that lists the most recent added products in the umbraco installation.

Requirements:
A documenttype with the alias: "Product"

System parameters:
$currentPage: The xmlnode of the current webpage requested (is set by the umbraco runtime)

Optional macro parameters:
$max: (numeric) defines the number of items listed, the default is 5 if the parameter is not supplied

Should be cached for eg. 100 seconds - it's performance intensive for an installation with many products/pages
-->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library"
	exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:variable name="max">
<xsl:choose>
<xsl:when test="string(//max) != ''"><xsl:value-of select="//max" /></xsl:when>
<xsl:otherwise>5</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::root/descendant-or-self::node [@nodeTypeAlias='Product']">
<xsl:sort select="@createDate" order="descending"/>
 <xsl:if test="position() &lt;= number($max)">
	<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a></li>
 </xsl:if>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>